let mta = require('../../utils/mta_analysis.js');
let fetch = require("../../utils/fetch");
Page({
	data: {
		urlAddress: getApp().globalData.imageUrl,
		type: '',
		isSend: 0, //0新用户  1忘记密码 2不可发送
		passWord: '',
		phoneNum: '',
		msg: "获取验证码",
		isCanSend: false


		// isShow: false,
		// styleList: ['noSelect_style', 'noSelect_style', 'noSelect_style', 'noSelect_style', 'noSelect_style', 'noSelect_style']

	},
	onLoad: function(options) {


	},
	onReady: function() {},
	onShow: function() {
		this.getBalancePassword();
	},
	onHide: function() {},
	onUnload: function() {},
	sendMsg: function(e) {
		var _self = this;
		console.log(e.currentTarget.dataset.type)
		if (!this.data.isCanSend) {
			fetch.showMyToast(_self, "验证码已发送")
			return
		}
		if (e.currentTarget.dataset.type == 0) {
			wx.request({
				url: getApp().globalData.baseUrl + '/applet/balance/pwd/sms/1.do',
				method: 'get',
				header: getApp().globalData.header,
				success: function(res) {
					_self.setData({

						msg: "验证码已发送",
						isCanSend: false
					})
					_self.countdown();
				}
			})

		} else if (e.currentTarget.dataset.type == 1) {
			wx.request({
				url: getApp().globalData.baseUrl + '/applet/balance/pwd/sms/2.do',
				method: 'get',
				header: getApp().globalData.header,
				success: function(res) {
					_self.setData({

						msg: "验证码已发送",
						isCanSend: false
					})
					_self.countdown();
				}
			})

		} else if (e.currentTarget.dataset.type == 2) {


		}

	},
	countdown: function() {
		var timeNum = 60;
		var _self = this;
		var timer = setInterval(function() {
			timeNum--;
			_self.setData({
				isCanSend: false,
				msg: timeNum + "s后可发送"
			})
			if (timeNum == 0) {
				clearInterval(timer)
				_self.setData({
					isCanSend: true,
					msg: "获取验证码"
				})
			}
		}, 1000)

	},
	getPassWord: function(e) {
		console.log(e.detail.value)
		this.setData({
			passWord: e.detail.value
		})
	},
	nextStop: function() {
		var _self = this;
		var souce = '';
		if (this.data.type == 0) {
			souce = 1; //新用户
		} else {
			souce = 2; //忘记密码
		}
		if (this.data.passWord.length >= 4) {
			wx.showLoading({
				title: '加载中',
				mask: true
			})
			wx.request({
				url: getApp().globalData.baseUrl + '/applet/balance/pwd/verify/' + souce + '/' + _self.data.passWord + '.do',
				method: 'get',
				header: getApp().globalData.header,
				success: function(res) {
					console.log(souce)
					console.log(_self.data.passWord)
					console.log(res)
					console.log(getApp().globalData.header)
					wx.hideLoading();
					if (res.data.code == 200) {

						if (res.data.obj) {

							wx.redirectTo({
								url: '../balanceSet/balanceSet?souce=' + souce
							})
						} else {
							fetch.showMyToast(_self, "验证码错误")
						}


					} else {
						fetch.showMyToast(_self, "请输入正确的验证码")
					}

				}
			})
		} else {
			fetch.showMyToast(_self, "请输入正确的验证码")
		}


	},
	getBalancePassword: function() {
		var _self = this;
		wx.showLoading({
			title: '加载中',
			mask: true
		})
		wx.request({
			url: getApp().globalData.baseUrl + '/applet/balance/pwd/type.do',
			method: 'get',
			header: getApp().globalData.header,
			success: function(res) {
				wx.hideLoading();
				if (res.data.code == 200) {
					console.log("*******")
					console.log(res)
					_self.setData({
						phoneNum: res.data.obj.phone,
						type: res.data.obj.type,
						isSend: res.data.obj.type,
						isCanSend: true
					})

				} else {
					fetch.showMyToast(_self, "服务器异常");
				}
			}

		})


	}



})